<template>
  <el-dialog
    class="variable-add-record"
    :title="dialogTitle"
    width="660px"
    :show-close="true"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <div>
      <el-form :rules="rules" ref="formRef" size="mini" :model="formData" label-width="140px">
        <el-form-item label="变量：" prop="variable">
          <el-input
            :disabled="dialogTitle === '编辑' && !isOperate"
            style="width: 80%"
            maxlength="30"
            show-word-limit
            clearable
            placeholder="请输入"
            v-model.trim="formData.variable"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="变量名：" prop="variableName">
          <el-input
            style="width: 80%"
            clearable
            :disabled="!isOperate"
            placeholder="请输入"
            maxlength="30"
            show-word-limit
            v-model="formData.variableName"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="变量类型：" prop="variableType">
          <el-select
            v-model="formData.variableType"
            placeholder="请选择"
            style="width: 80%"
            :disabled="!isOperate"
            @change="handleVariableTypeChange"
          >
            <el-option
              v-for="item in variableTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 单选、多选 -->
        <div v-if="formData.variableType === '10' || formData.variableType === '20'">
          <el-form-item label="编码名称：" prop="codeName">
            <el-input style="width: 80%" disabled placeholder="请选择内容" v-model="formData.codeName"></el-input>
            <el-popover placement="right" width="400" title="编码名称" trigger="click" v-model="codeNameWindowVisible">
              <div style="width: 100%; height: 600px; overflow-y: auto">
                <el-radio-group
                  v-model="searchRadio"
                  style="margin-bottom: 4px; margin-top: 8px; display: flex; justify-content: space-between"
                >
                  <div>
                    <el-radio-button label="1">ALL</el-radio-button>
                    <el-radio-button label="2">本表</el-radio-button>
                  </div>

                  <el-button size="mini" type="danger" round @click="handleCloseCodeNameWindow">关闭窗口</el-button>
                </el-radio-group>
                <el-input style="width: 96%" placeholder="输入关键字进行筛选" clearable v-model="filterText">
                </el-input>
                <el-tree
                  class="filter-tree"
                  :data="generalCodeList"
                  @node-click="handleNodeClick"
                  :props="{
                    value: 'value',
                    label: 'label',
                  }"
                  :filter-node-method="filterNode"
                  ref="tree"
                >
                  <template slot-scope="{ data }">
                    <span :title="data.title ? data.title : ''">{{ data.label }}</span>
                  </template>
                </el-tree>
              </div>
              <el-button
                slot="reference"
                icon="el-icon-more"
                style="margin-left: 8px"
                @click="handleGetAssistSetting"
              ></el-button>
            </el-popover>
          </el-form-item>
          <!-- 单选 -->
          <el-form-item label="编码排列方式：" prop="codeArrangement" v-if="formData.variableType === '10'">
            <el-select v-model="formData.codeArrangement" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
              <el-option
                v-for="item in arrangementModeList"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <!-- 多选 -->
          <el-form-item label="编码排列方式：" prop="codeArrangement" v-if="formData.variableType === '20'">
            <el-select v-model="formData.codeArrangement" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
              <el-option
                v-for="item in checkBoxModeList"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="每行编码数量：" v-if="formData.codeArrangement === 2" prop="codeNumber">
            <el-input-number :disabled="!isOperate" v-model="formData.codeNumber" :step="1" step-strictly style="width: 80%"></el-input-number>
          </el-form-item>
        </div>
        <!-- 日期 -->
        <el-form-item label="允许修改录入日期：" v-if="formData.variableType === '30'">
          <el-radio-group v-model="formData.configure.modifyEntryDate" :disabled="!isOperate">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 时间 -->
        <el-form-item label="精确度：" v-if="formData.variableType === '40'">
          <el-select v-model="formData.configure.accuracy" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
            <el-option
              v-for="item in accuracyTypeList"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 日期时间 -->
        <el-form-item label="精确度：" v-if="formData.variableType === '50'">
          <el-select v-model="formData.configure.accuracy" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
            <el-option
              v-for="item in dateTimeAccuracyTypeList"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 数值 -->
        <el-form-item label="格式：" v-if="formData.variableType === '60' || formData.variableType === '80'">
          <el-input
            :disabled="!isOperate"
            style="width: 80%"
            clearable
            placeholder="n.m n表示有效位数，m表示小数点后位数"
            maxlength="30"
            v-model="formData.configure.form"
          ></el-input>
        </el-form-item>

        <!-- 字符日期 -->
        <el-form-item label="精确度：" v-if="formData.variableType === '90'">
          <el-select v-model="formData.configure.accuracy" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
            <el-option
              v-for="item in charDateAccuracyTypeList"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 字符时间 -->
        <el-form-item label="精确度：" v-if="formData.variableType === '100'">
          <el-select v-model="formData.configure.accuracy" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
            <el-option
              v-for="item in charDateTimeAccuracyTypeList"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 图片 -->
        <div v-if="formData.variableType === '120'">
          <el-form-item label="数量：">
            <el-input-number
              v-model="formData.configure.number"
              :step="1"
              step-strictly
              style="width: 80%"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="支持OCR：">
            <el-radio-group v-model="formData.configure.ocr">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <div v-if="formData.variableType === '70' || formData.variableType === '110'">
          <el-form-item label="辅助录入设定：" >
            <el-input
              type="textarea"
              style="width: 80%"
              :rows="4"
              disabled
              placeholder="请选择内容"
              v-model="formData.configure.crfText"
            ></el-input>
            <el-popover placement="right" width="400" title="辅助录入设定" trigger="click">
              <div>
                <el-form-item label="类型：">
                  <el-radio-group v-model="formData.configure.type" @change="handleTypeChange">
                    <el-radio label="1">固定字典</el-radio>
                    <el-radio label="2">CRF</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="固定字典：" v-if="formData.configure.type === '1'">
                  <el-input
                    type="textarea"
                    style="width: 200px"
                    :rows="2"
                    placeholder="字典项用|分割,例如：男|女"
                    v-model="formData.configure.crfText"
                  ></el-input>
                </el-form-item>
                <div v-if="formData.configure.type === '2'">
                  <h4>条件设置</h4>
                  <el-form-item label="条件变量：">
                    <el-select
                      v-model="formData.configure.conditionVariable"
                      placeholder="请选择"
                      style="width: 80%"
                      @change="handleConditionValue"
                    >
                      <el-option
                        v-for="item in variableConfigList"
                        :key="item.variable"
                        :disabled="item.variableType !== '10' && item.variableType !== '20'"
                        :label="item.variableName"
                        :value="item.variable"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="条件变量取值：">
                    <el-select v-model="formData.configure.conditionValue" placeholder="请选择" style="width: 80%">
                      <el-option
                        v-for="item in variableValueList"
                        :key="item.codeValue"
                        :label="item.codeDescribe"
                        :value="item.codeValue"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <h4>转抄设置</h4>
                  <el-form-item label="访视：">
                    <el-select
                      v-model="formData.configure.visits"
                      placeholder="请选择"
                      style="width: 80%"
                      @change="handleVisitsChange"
                    >
                      <el-option
                        v-for="item in sourceTableInterviewList"
                        :key="item.id"
                        :label="item.visitName"
                        :value="item.id"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="表：">
                    <el-select
                      v-model="formData.configure.crfId"
                      placeholder="请选择"
                      style="width: 80%"
                      @change="handleSourceTableChange"
                    >
                      <el-option
                        v-for="item in sourceTableList"
                        :key="item.id"
                        :label="item.tableName"
                        :value="item.id"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="变量：">
                    <el-select
                      v-model="formData.configure.crfNameVariableList"
                      multiple
                      placeholder="请选择"
                      style="width: 80%"
                    >
                      <el-option
                        v-for="item in fieldList"
                        :key="item.variable"
                        :label="item.variableName"
                        :value="item.variable"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </div>
                <div class="assist-setting-submit">
                  <el-button type="primary" @click="handleAssistDicSubmit">确定</el-button>
                </div>
              </div>
              <el-button
                slot="reference"
                icon="el-icon-more"
                style="margin-left: 8px"
                @click="handleGetAssistSetting"
              ></el-button>
            </el-popover>
          </el-form-item>
          <el-form-item label="文本区只读：">
            <el-radio-group v-model="formData.configure.isOnlyRead" :disabled="!isOperate">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-form-item label="只读：" prop="readOnly" >
          <el-radio-group v-model="formData.readOnly" :disabled="!isOperate">
            <el-radio label="0">是</el-radio>
            <el-radio label="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="必填：" prop="required">
          <el-radio-group v-model="formData.required" :disabled="!isOperate">
            <el-radio label="0">是</el-radio>
            <el-radio label="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="默认值：" v-if="formData.variableType === '10' || formData.variableType === '20'">
          <el-select v-model="formData.defaultValue" placeholder="请选择" style="width: 80%" :disabled="!isOperate">
            <el-option
              v-for="item in defaultValueList"
              :key="item.codeValue"
              :label="item.codeDescribe"
              :value="item.codeValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="默认值：" v-else>
          <el-input style="width: 80%" clearable placeholder="请输入" maxlength="30" v-model="formData.defaultValue" :disabled="!isOperate">
          </el-input>
        </el-form-item>
        <el-form-item label="录入说明：">
          <el-input style="width: 80%" clearable placeholder="请输入" maxlength="30" v-model="formData.entry" :disabled="!isOperate">
          </el-input>
        </el-form-item>
        <el-form-item label="正则表达式：">
          <el-input style="width: 80%" clearable placeholder="请输入" maxlength="30" v-model="formData.regEx" :disabled="!isOperate">
          </el-input>
        </el-form-item>
        <el-form-item label="SAS导出格式：" prop="sasDerive">
          <el-input style="width: 80%" clearable placeholder="请输入" maxlength="30" v-model="formData.sasDerive" :disabled="!isOperate">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button :loading="loading" size="small" type="primary" @click="handleSave">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { mapActions } from 'vuex'
import { variableTypeList } from '@/utils/enums/ecrf-design.js'
import {
  arrangementModeList,
  dateTimeAccuracyTypeList,
  accuracyTypeList,
  charDateAccuracyTypeList,
  charDateTimeAccuracyTypeList,
  defaultSASValue,
  checkBoxModeList
} from '../data'

export default {
  props: {
    editData: Object,
    dialogVisible: Boolean,
    dialogTitle: String,
    referenceTableList: Array,
    searchParams: Object,
    variableConfigList: Array,
    isOperate: Boolean
  },
  data() {
    return {
      rules: {
        variable: [
          { required: true, message: '请输入', trigger: 'blur' },
          { pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/, message: '必须字母开头，由字母数字下划线组合', trigger: 'blur' },
        ],
        variableName: [{ required: true, message: '请输入', trigger: 'blur' }],
        variableType: [{ required: true, message: '请选择', trigger: 'blur' }],
        readOnly: [{ required: true, message: '请选择', trigger: 'blur' }],
        required: [{ required: true, message: '请选择', trigger: 'blur' }],
        sasDerive: [{ required: true, message: '请输入', trigger: 'blur' }],
        codeName: [{ required: true, message: '请选择', trigger: 'blur' }],
        codeArrangement: [{ required: true, message: '请选择', trigger: 'blur' }],
        codeNumber: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
      loading: false,
      defaultFormData: {
        variable: '',
        variableName: '',
        variableType: '',
        readOnly: '1',
        required: '1',
        defaultValue: '',
        entry: '',
        regEx: '',
        sasDerive: '',
        codeName: '',
        codeArrangement: 1,
        codeNumber: '',
        configure: {
          isOnlyRead: '1',
          codeName: '',
          codeArrangement: 1,
          modifyEntryDate: '',
          accuracy: '',
          number: '',
          ocr: '',
          form: '',
          crfText: '',
          type: 1,
          dictionaryValue: '',
          conditionVariable: '',
          conditionValue: '',
          crfId: '',
          visits: '',
        },
      },
      formData: {},
      filterText: '',
      variableTypeList,
      arrangementModeList,
      accuracyTypeList,
      charDateAccuracyTypeList,
      charDateTimeAccuracyTypeList,
      defaultSASValue,
      dateTimeAccuracyTypeList,
      generalCodeList: [],
      defaultValueList: [],
      configType: {
        1: '固定字典',
        2: 'CRF',
      },
      sourceTableInterviewList: [],
      sourceTableList: [],
      variableValueList: [],
      fieldList: [],
      searchRadio: '1',
      codeNameWindowVisible: false,
      checkBoxModeList
    }
  },

  watch: {
    dialogVisible(val) {
      if (val) {
        this.formData = this.editData.id ? { ...this.editData } : { ...this.defaultFormData, ...this.editData }
        if (this.formData.variableType === '10' || this.formData.variableType === '20') {
          this.getEncodingList()
        }
        if (this.formData.variableType === '70' || this.formData.variableType === '110') {
          this.handleConditionValue(this.formData.configure.conditionVariable)
          this.getInterviewList()

          console.log(11111, this.formData.configure.visits)
          this.getTableList(this.formData.configure.visits, 'init')

          console.log(2222222, this.formData.configure.crfId)
          
        }
      } else {
        this.formData = { ...this.defaultFormData }
      }
    },
    filterText(val) {
      this.$refs.tree.filter(val)
    },
    searchRadio(val) {
      if (val) {
        this.filterText = ''
        this.handleGetCodeList()
      }
    },
  },

  methods: {
    ...mapActions('eCRFDesign', [
      'addVariableConfig',
      'editVariableConfig',
      'qryAllGeneralCodeList',
      'qryCodeValueByCodeNameNoLoading',
      'qrySourceTableInterviewList',
      'qrySourceTableList',
      'qryVariableConfigListNoLoading',
    ]),

    // 关闭编码名称的树结构弹窗
    handleCloseCodeNameWindow() {
      this.codeNameWindowVisible = false
    },

    // 筛选
    filterNode(value, data, node) {
      if (!value) {
        return true
      } else {
        let parentNode = node.parent
        let labels = [data.label]
        let level = 1
        while (level < node.level) {
          labels = [...labels, parentNode.data.label]
          parentNode = parentNode.parent
          level++
        }
        return labels.some(label => label.indexOf(value) !== -1)
      }
    },

    // 选中树节点
    handleNodeClick(data) {
      if (!data.children) {
        this.formData.codeName = data.label
        this.formData.defaultValue = ''
        this.handleModuleNameChange(data.label)
      }
    },

    // 控制根据本表和AL查询编码的条件
    handleGetCodeList() {
      this.getEncodingList()
    },

    // 关闭取消
    handleClose() {
      this.formData = { ...this.defaultFormData }
      this.$emit('handleCancel')
    },

    handleAssistDicSubmit() {
      if (!this.formData.configure.conditionVariable) {
        this.$message.error('请选择条件变量')
        return ''
      } else {
        this.variableConfigList.map((vItem, vIndex) => {
          if (vItem.variable === this.formData.configure.conditionVariable) {
            this.formData.configure.conditionFieldName = vItem.variableName
          }
        })
      }

      if (!this.formData.configure.conditionValue) {
        this.$message.error('请选择变量取值')
        return ''
      } else {
        this.variableValueList.map((vItem, vIndex) => {
          if (vItem.codeValue === this.formData.configure.conditionValue) {
            this.formData.configure.conditionValueName = vItem.codeDescribe
          }
        })
      }
      if (!this.formData.configure.visits) {
        this.$message.error('请选择访视')
        return ''
      } else {
        this.sourceTableInterviewList.map((sItem, vIndex) => {
          if (sItem.id === this.formData.configure.visits) {
            this.formData.configure.visitCnName = sItem.visitName
          }
        })
      }
      if (!this.formData.configure.crfId) {
        this.$message.error('请选择访视表')
        return ''
      } else {
        this.sourceTableList.map((sItem, vIndex) => {
          if (sItem.id === this.formData.configure.crfId) {
            this.formData.configure.crfName = sItem.tableCode
            this.formData.configure.crfCnName = sItem.tableName
          }
        })
      }
      if (!this.formData.configure.crfNameVariableList) {
        this.$message.error('请选择变量')
        return ''
      } else {
        this.formData.configure.fieldCnNames = []
        this.formData.configure.crfNameVariableList.map((cItem, cIndex) => {
          this.fieldList.map((fItem, fIndex) => {
            if (cItem === fItem.variable) {
              this.formData.configure.fieldCnNames.push(fItem.variableName)
            }
          })
        })
      }

      const { type, conditionFieldName, conditionValueName, visitCnName, crfCnName, fieldCnNames, crfText } =
        this.formData.configure

      let text = ''
      if (type === '2') {
        text = ` 类型：${
          this.configType[type]
        } \n 条件变量：${conditionFieldName} \n 条件变量取值：${conditionValueName} \n 访视：${visitCnName} \n 表： ${crfCnName} \n 变量: ${fieldCnNames.join(
          ','
        )}`
      } else {
        text = ` 类型：${this.configType[type]} \n 固定字典: ${crfText}`
        this.formData.configure.conditionVariable = ''
        this.formData.configure.conditionValue = ''
        this.formData.configure.visits = ''
        this.formData.configure.crfId = ''
        this.formData.configure.crfNameVariableList = ''
      }

      this.formData.configure.crfText = text
      console.log('this.formData.configure', this.formData.configure)
    },

    // 固定字典-CRF切换请求对应数据
    handleTypeChange(value) {
      if (value === '2') {
        this.getInterviewList()
      }
      if (value === '1') {
        this.formData.configure.crfText = ''
      }
    },

    // 访视change事件
    handleVisitsChange(value) {
      this.formData.configure.crfId = ''
      this.formData.configure.crfNameVariableList = ''
      // 获取访视表
      this.getTableList(value)
    },

    // 条件变量取值
    handleConditionValue(value) {
      // this.formData.configure.crfNameVariableList = ''
      let selectedItem = {}
      this.variableConfigList.map((vItem, vIndex) => {
        if (vItem.variable === value) {
          selectedItem = { ...vItem }
        }
      })
      if (selectedItem.id) {
        console.log('selectedItem', selectedItem)
        const codeName = selectedItem.variableTypeValue.codeName.split('|')[0]
        this.getVariableValueList(codeName)
      }
    },

    // 查询变量取值下拉选项
    getVariableValueList(codeName) {
      const params = {
        ...this.searchParams,
        code_name: codeName,
      }

      this.qryCodeValueByCodeNameNoLoading({ params }).then(res => {
        const { code, data } = res
        if (code === 200) {
          this.variableValueList = data
        }
      })
    },

    // 查询访视数据
    getInterviewList() {
      const params = {
        ...this.searchParams,
        environment: '0',
      }
      console.log('params', params)
      this.qrySourceTableInterviewList({ params }).then(res => {
        const { data, code } = res
        if (code === 200) {
          this.sourceTableInterviewList = data
        }
      })
    },

    // 查询访视表
    getTableList(value, type) {
      console.log(value)
      const params = {
        ...this.searchParams,
        environment: '0',
        visitId: value,
      }
      this.qrySourceTableList({ params }).then(res => {
        const { data, code } = res
        if (code === 200) {
          this.sourceTableList = data
          if (type === 'init') {
            this.handleSourceTableChange(this.formData.configure.crfId, 'init')
          }
        }
      })
    },

    // 查询表字段
    handleSourceTableChange(value, type) {
      console.log('value', value)
      let surface = ''
      if (type !== 'init') {
        this.formData.configure.crfNameVariableList = ''
      }
      this.sourceTableList.map((sItem, vIndex) => {
        if (sItem.id === value) {
          surface = sItem.tableCode
        }
      })
      if (surface) {
        const params = {
          ...this.searchParams,
          surface,
        }
        this.qryVariableConfigListNoLoading({ params }).then(res => {
          const { data, code } = res
          if (code === 200) {
            this.fieldList = data
          }
        })
      }
    },

    // 保存提交
    handleSave() {
      this.loading = true
      this.$refs.formRef.validate(valid => {
        if (valid) {
          const data = {
            ...this.formData,
            ...this.searchParams,
            databaseCrfSurface: this.searchParams.surface,
          }
          if (data.variableType === '10' || data.variableType === '20') {
            if (!this.formData.codeName) {
              this.$message.error('请选择编码名称')
              this.loading = false
              return
            }
            data.configure.codeName = this.formData.codeName
            data.configure.codeArrangement = this.formData.codeArrangement
            data.configure.number = this.formData.codeNumber
          }
          if (data.id) {
            this.editVariableConfig({ data }).then(res => {
              const { code } = res
              if (code === 200) {
                this.$message({
                  message: '保存成功',
                  type: 'success',
                })
                this.$refs.formRef.resetFields()
                this.$emit('handleCancel', 'refresh')
              }
              this.loading = false
            })
          } else {
            this.addVariableConfig({ data }).then(res => {
              const { code } = res
              if (code === 200) {
                this.$message({
                  message: '保存成功',
                  type: 'success',
                })
                this.$refs.formRef.resetFields()
                this.$emit('handleCancel', 'refresh')
              }
              this.loading = false
            })
          }
        } else {
          this.loading = false
          return false
        }
      })
    },

    // 获取默认值下拉选项
    handleModuleNameChange(value) {
      // 根据编码名称获取编码值
      const codeName = value.split('|')[0]
      const params = {
        ...this.searchParams,
        code_name: codeName,
      }
      console.log(params, 'params')

      this.qryCodeValueByCodeNameNoLoading({ params }).then(res => {
        const { code, data } = res
        if (code === 200) {
          this.defaultValueList = data
          console.log('this.defaultValueList', this.defaultValueList)
        }
      })
    },

    // 变量类型onChange事件
    handleVariableTypeChange(value) {
      if (value) {
        this.formData.sasDerive = this.defaultSASValue[value] ? this.defaultSASValue[value] : ''
      }
      if (value === '30') {
        this.formData.configure.modifyEntryDate = 1
      }
      if (value === '40') {
        this.formData.configure.accuracy = '1'
      }
      if (value === '50') {
        this.formData.configure.accuracy = '2'
      }
      if (value === '90') {
        this.formData.configure.accuracy = '1'
      }
      if (value === '100') {
        this.formData.configure.accuracy = '1'
      }

      if (value === '10' || value === '20') {
        this.formData.codeName = ''
        this.formData.codeArrangement = 1
        this.getEncodingList()
      }
      if (value === '60' || value === '80') {
        this.formData.configure.form = ''
      }
    },

    // 查询编码列表
    getEncodingList() {
      const params = {
        ...this.searchParams,
      }
      if (this.searchRadio === '1') {
        params.thisTable = ''
      } else if (this.searchRadio === '2') {
        params.thisTable = this.searchParams.surface
      }
      this.qryAllGeneralCodeList({ params }).then(res => {
        console.log(res, 'res')
        const { code, data } = res
        if (code === 200) {
          this.generalCodeList = this.formateData(data)
          console.log('data111111', this.generalCodeList)
        }
        this.loading = false
      })
    },

    formateData(data) {
      data.map((dItem, dIndex) => {
        dItem.children = []
        if (dItem.codeGroupcn) {
          dItem.label = dItem.codeGroupcn + '|' + dItem.codeGroup
          dItem.value = dItem.codeGroupcn
        }
        if (dItem.codeNameCn) {
          dItem.label = dItem.codeName + '|' + dItem.codeNameCn
          dItem.value = dItem.codeName + '|' + dItem.codeNameCn
          dItem.title = this.formateTitle(dItem.codeValueVOS)
          delete dItem.codeValueVOS
          delete dItem.children
        }
        if (dItem.codeNameCnGroupVOS && dItem.codeNameCnGroupVOS.length > 0) {
          dItem.children.unshift(...dItem.codeNameCnGroupVOS)
          this.formateData(dItem.codeNameCnGroupVOS)
        }
      })
      return data
    },

    // 鼠标悬浮展示编码值
    formateTitle(list) {
      const arr = []
      list.map((lItem, lIndex) => {
        const text = lItem.codeValue + ':' + lItem.codeDescribe
        arr.push(text)
      })
      return arr.join(';')
    },

    // 打开辅助设置弹框要做哪些内容
    handleGetAssistSetting() {},
  },
}
</script>
<style lang="scss" scoped>
@import './add-variable.scss';
/deep/.el-tree-node:focus > .el-tree-node__content {
  color: #753cca;
  background-color: #dccde9; //选中背景色
}
</style>
